package com.neuedu.thread.wait;

// 仓库(有界缓冲区)
class Storage {
	private int count = 0;
	public synchronized void set(){
		if(count>=5){
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		count++;
		System.out.println("生产了一个，仓库中有：" + count);
		this.notify();
	}
	public synchronized void get(){
		if(count<=0){
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		count--;
		System.out.println("消费了一个，仓库中有：" + count);
		this.notify();
	}
}

